﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.SessionState;
using Rison.DataAccess.Data.ZJCP;
using Rison.BusinessFacade.Common;

namespace Rison.Web.ZJCP.ashx
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SaveDetail : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/plain";
            if (!CurrentLoginedUser.Logined)
            {
                context.Response.Write("false");
            }
            else
            {
                string mark = "";
                for (int i = 0; i < 53; i++)
                {
                    if (i > 0)
                    {
                        mark += ",";
                    }
                    string temp = context.Request.Params[String.Format("textfield{0}", i + 1)];
                    if (!String.IsNullOrEmpty(temp))
                    {
                        mark += int.Parse(temp.Trim());
                    }

                }
                saveMark(mark, context.Request.Params["departId"], CurrentLoginedUser.UserId);
                context.Response.Write("true");
                
            }
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private Boolean saveMark(string mark, string departId, string exId)
        {
            string sql = String.Format("update ExpertDepart set mark='{0}' where depart_id='{1}' and ex_id='{2}'",mark.Trim(), departId, exId);
            int result = DbAccess.executeUpdate(sql);
            return result == 1;
        }
    }
}
